﻿(function ($) {
    function _validate(formId, urles, messages) {
         $.my_validate("#" + formId, urles, messages);

       // var vali_val = $.check_validate("#" + formId);
        // $('#' + formId).submit(function () {            
        //     //return false;
        //    if ($.check_validate("#" + formId)) {
        //        $(this).ajaxSubmit(function (data) {
        //            var jsonData = $.parseJSON(data);
        //            Success(jsonData);
        //        });
        //    }
        //    return false;
        //});
    }
    $.extend($, {
        validate_video: function (formId) {
            var urles = {
                client_id: {
                    required: true,
                    maxlength: 16,
                    minlength: 16
                    //isZipCode:true
                },
                client_secret: {
                    required: true,
                    maxlength: 32,
                    minlength: 32
                },
                refresh_token: {
                    required: true,
                    maxlength: 32,
                    minlength: 32
                }
            };
            var messages = {
                client_id: {
                    required: 'client_id 必须填写',
                    maxlength: 'client_id 长度为16个字符',
                    minlength: 'client_id 长度为16个字符',
                },
                client_secret: {
                    required: 'client_secret 必须填写',
                    maxlength: 'client_secret 长度为32个字符',
                    minlength: 'client_secret 长度为32个字符',
                },
                refresh_token: {
                    required: 'refresh_token 必须填写',
                    maxlength: 'refresh_token 长度为32个字符',
                    minlength: 'refresh_token 长度为32个字符',
                }
            };
            _validate(formId, urles, messages)
        },
        validate_about: function (formId) {
            var urles = {
                title: {
                    required: true,
                },
            };
            var messages = {
                title: {
                    required: '标题 必须填写',
                },
            };
            _validate(formId, urles, messages)
        },

        validate_culture: function (formId) {
            var urles = {
                ctitle: {
                    required: true,
                },
            };
            var messages = {
                ctitle: {
                    required: '标题 必须填写',
                },
            };
            _validate(formId, urles, messages)
        },
        validate_visionaries: function (formId) {
            var urles = {
                vtitle: {
                    required: true,
                },
            };
            var messages = {
                vtitle: {
                    required: '标题 必须填写',
                },
            };
            _validate(formId, urles, messages)
        },
        validate_questionWeight: function (formId) {
            var urles = {
                weight: {
                    required: true,
                    digits: true,
                    min: 0
                },
            };
            var messages = {
                weight: {
                    required: '权重必须填写',
                    digits: '请输入整数',
                    min: '权重最小值为0'
                },
            };
            _validate(formId, urles, messages)
        },
        validate_question: function (formId) {
            var urles = {
                weight: {
                    required: true,
                    digits: true,
                    min: 0
                },
                q_contents: {
                    maxlength: 500,
                    required: true,
                },
                a_contents: {
                    maxlength: 500,
                    required: true,
                },
            };
            var messages = {
                weight: {
                    required: '权重必须填写',
                    digits: '请输入整数',
                    min: '权重最小值为0'
                },
                q_contents: {
                    maxlength: "问题描述最长为500字符",
                    required: "问题描述必须填写",
                },
                a_contents: {
                    maxlength: "问题答案最长为500字符",
                    required: "问题答案必须填写",
                },
            };
            _validate(formId, urles, messages)
        },
        validate_eventWeight: function (formId) {//事件列表权重验证
            var urles = {
                weight: {
                    required: true,
                    digits: true,
                    min: 0
                },
            };
            var messages = {
                weight: {
                    required: '权重必须填写',
                    digits: '请输入整数',
                    min: '权重最小值为0'
                },
            };
            _validate(formId, urles, messages)
        },
        validate_event: function (formId) {//事件表单验证
            var urles = {
                weight: {
                    required: true,
                    digits: true,
                    min: 0
                },
                title: {
                    required: true,
                },
                description: {
                    maxlength: 80
                }
            };
            var messages = {
                weight: {
                    required: '权重必须填写',
                    digits: '请输入整数',
                    min: '权重最小值为0'
                },
                title: {
                    required: '标题必须填写',
                },
                description: {
                    maxlength: "描述最长为80个字符"
                }
            };
            _validate(formId, urles, messages)
        },
        validate_newWeight: function (formId) {//新闻列表权重验证
            var urles = {
                weight: {
                    required: true,
                    digits: true,
                    min: 0
                },
            };
            var messages = {
                weight: {
                    required: '权重必须填写',
                    digits: '请输入整数',
                    min: '权重最小值为0'
                },
            };
            _validate(formId, urles, messages)
        },
        validate_new: function (formId) {//新闻表单验证
            var urles = {
                weight: {
                    required: true,
                    digits: true,
                    min: 0
                },
                title: {
                    required: true,
                },
                keyword: {
                    maxlength: 200
                },
                description: {
                    maxlength: 200
                }
            };
            var messages = {
                weight: {
                    required: '权重必须填写',
                    digits: '请输入整数',
                    min: '权重最小值为0'
                },
                title: {
                    required: '标题必须填写',
                },
                keyword: {
                    maxlength: "关键字最长为200个字符"
                },
                description: {
                    maxlength: "描述最长为200个字符"
                }
            };
            _validate(formId, urles, messages)
        },
        validate_downWeight: function (formId) {//课件列表权重验证
            var urles = {
                weight: {
                    required: true,
                    digits: true,
                    min: 0
                },
            };
            var messages = {
                weight: {
                    required: '权重必须填写',
                    digits: '请输入整数',
                    min: '权重最小值为0'
                },
            };
            _validate(formId, urles, messages)
        },
        validate_down: function (formId) {//课件表单验证
            var urles = {
                weight: {
                    required: true,
                    digits: true,
                    min: 0
                },
                title: {
                    required: true,
                },
                downurl: {
                    required: true,
                },
                imgurl: {
                    required: true,
                }
            };
            var messages = {
                weight: {
                    required: '权重必须填写',
                    digits: '请输入整数',
                    min: '权重最小值为0'
                },
                title: {
                    required: '标题必须填写',
                },
                downurl: {
                    required: "课件必须上传"
                },
                imgurl: {
                    required: "图片必须上传"
                }
            };
            _validate(formId, urles, messages)
        },
        validate_project: function (formId) {
            var urles = {
                title: {
                    required: true,
                },
                description: {
                    maxlength: 80
                }
            };
            var messages = {
                title: {
                    required: '标题 必须填写',
                },
                description: {
                    maxlength: "描述最长为80个字符"
                }
            };
            _validate(formId, urles, messages)
        },
        validate_multimedia: function (formId) {
            var urles = {
                mtitle: {
                    required: true,
                },
                mdescription: {
                    maxlength: 80
                }
            };
            var messages = {
                mtitle: {
                    required: '标题 必须填写',
                },
                mdescription: {
                    maxlength: "描述最长为80个字符"
                }
            };
            _validate(formId, urles, messages)
        },

        validate_didacticsWeight: function (formId) {//教学法列表权重验证
            var urles = {
                weight: {
                    required: true,
                    digits: true,
                    min: 0
                },
            };
            var messages = {
                weight: {
                    required: '权重必须填写',
                    digits: '请输入整数',
                    min: '权重最小值为0'
                },
            };
            _validate(formId, urles, messages)
        },
        validate_didactics: function (formId) {//教学法表单验证
            var urles = {
                weight: {
                    required: true,
                    digits: true,
                    min: 0
                },
                title: {
                    required: true,
                },
                description: {
                    maxlength: 47
                }
            };
            var messages = {
                weight: {
                    required: '权重必须填写',
                    digits: '请输入整数',
                    min: '权重最小值为0'
                },
                title: {
                    required: '标题必须填写',
                },
                description: {
                    maxlength: "描述最长为47个字符"
                }
            };
            _validate(formId, urles, messages)
        },
        validate_join: function (formId) {
            var urles = {
                title: {
                    required: true,
                },
            };
            var messages = {
                title: {
                    required: '标题 必须填写',
                },
            };
            _validate(formId, urles, messages)
        },
        validate_config: function (formId) {
            var urles = {
                title: {
                    required: true,
                },
                sitelogo: {
                    required: true,
                },
                keyword: {
                    required: true,
                },
                description: {
                    required: true,
                },
            };
            var messages = {
                title: {
                    required: '标题 必须填写',
                },
                sitelogo: {
                    required: '网站Logo 必须填写',
                },
                keyword: {
                    required: '网站关键字 必须填写',
                },
                description: {
                    required: '网站描述 必须填写',
                },
            };
            _validate(formId, urles, messages)
        },
        validate_contact: function (formId) {
            var urles = {

            };
            var messages = {

            };
            _validate(formId, urles, messages)
        },
        validate_user: function (formId, mt) {

            var urles = {
                user_account: {
                    required: true,
                    regex: "^\\w+$",
                   
                    rangelength: [5, 16],
                    remote: {
                        url: '/admin/user/check_unique?mark=' + mt,
                        type: 'get',
                        dataType: 'json',
                    }
                },
                user_pass: {
                    required: true,
                    rangelength: [5, 16],
                },
                user_name: {
                    required: true,
                    rangelength: [2, 16],
                },
                passconf: {
                    required: true,
                    rangelength: [5, 16],
                    equalTo: '#user_pass'
                },
                user_tel: {
                    required: true,
                    regex_tel: /^(0[0-9]{2,3}\-)?([2-9][0-9]{6,7})+(\-[0-9]{1,4})?$/,
                },
                user_phone: {
                    required: true,
                    regex_tel: /^(0|86|17951)?(13[0-9]|15[012356789]|17[01678]|18[0-9]|14[57])[0-9]{8}$/,
                }

            };
            var messages = {
                user_account: {
                    required: '用户名必填',
                    regex: "用户名只能以数字",
                    rangelength: '用户名长度为5-16个字符',
                    remote: '用户名已存在',
                },
                user_pass: {
                    required: '密码必填',
                    rangelength: '密码长度为5-16个字符',
                },
                user_name: {
                    required: '真实名称必填',
                    rangelength: '真实名称长度为2-16个字符',
                },
                passconf: {
                    required: '密码确认必填',
                    rangelength: '密码确认长度为5-16个字符',
                    equalTo: '密码不一致'
                },
                user_tel: {
                    required: "请填写电话",
                    regex_tel: "电话格式错误",
                },
                user_phone: {
                    required: "请填写手机",
                    regex_tel: "手机格式错误",
                }
            };
            _validate(formId, urles, messages)
        },
        //validate_menu: function (formId, mt, mlevel) {
        //    //var mlevel = $("#mlevel").val();
        //    //alert(mlevel);
        //    var urles = {
        //        mctrl: {
        //            required: true,
        //            regex: "^[A-Za-z]+$",
        //            rangelength: [2, 15],
        //        },
        //        mtitle: {
        //            required: true,
        //            rangelength: [1, 10],
        //        },
        //        mact: {
        //            required: true,
        //            rangelength: [2, 15],
        //        },
        //    };
        //    var messages = {
        //        mctrl: {
        //            required: 'url必填',
        //            regex: "url为字母，输入不正确",
        //            rangelength: 'url长度为2-15个字符',
        //            //remote: 'url已存在'
        //        },
        //        mtitle: {
        //            required: '栏目名称必填',
        //            rangelength: '栏目名称长度为1-10个字符',
        //        },
        //        mact: {
        //            required: 'url必填',
        //            rangelength: 'url长度为2-15个字符',
        //        },
        //    };
        //    _validate(formId, urles, messages)
        //},
        validate_material: function (formId) {
            var urles = {
                title: {
                    required: true,
                },
            };
            var messages = {
                title: {
                    required: '材质必填',
                },
            };
            _validate(formId, urles, messages)
        },
        validate_style: function (formId) {
            var urles = {
                title: {
                    required: true,
                },
            };
            var messages = {
                title: {
                    required: '材质必填',
                },
            };
            _validate(formId, urles, messages)
        },
        validate_color: function (formId) {
            var urles = {
                title: {
                    required: true,
                },
                colorkey: {
                    required: true,
                },
            };
            var messages = {
                title: {
                    required: '颜色描述必填',
                },
                colorkey: {
                    required: "色值必须填写或者选择",
                },
            };
            _validate(formId, urles, messages)
        },
        validate_size: function (formId) {
            var urles = {
                title: {
                    required: true,
                },
            };
            var messages = {
                title: {
                    required: '尺寸描述必填',
                },
            };
            _validate(formId, urles, messages)
        },
        validate_goods: function (formId) {
            var urles = {
                title: {
                    required: true,
                },
                shop_price: {
                    required: true,
                    regex_money: /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/
                },
                market_price: {
                    required: true,
                    regex_money: /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/
                },
                imgurl: {
                    required: true,
                },
                discount: {
                    required: true,
                    number:true,
                    min: 0,
                    max:10
                }
            };
            var messages = {
                title: {
                    required: '商品名称必填',
                },
                shop_price: {
                    required: '价格必须填写',
                    regex_money: "请输入正确的价格"
                },
                market_price: {
                    required: '价格必须填写',
                    regex_money: "请输入正确的价格"
                },
                imgurl: {
                    required: "图片必须上传",
                },
                weight: {
                    required: true,
                    digits: true,
                    min: 0
                },
                discount: {
                    required: "折扣价必须填写",
                    number: "请输入数字",
                    min: "最小折扣为0",
                    max: "最大折扣为9.9"
                }
            };
            _validate(formId, urles, messages)
        },
        validate_goodsimg: function (formId) {
            var urles = {
                imgurl: {
                    required: true,
                },
            };
            var messages = {
                imgurl: {
                    required: '商品图片必须上传',
                },
            };
            _validate(formId, urles, messages)
        },
        validate_inventory: function (formId) {
            var urles = {
                inventory_count: {
                    required: true,
                    digits: true,
                    min: 0
                },
            };
            var messages = {
                inventory_count: {
                    required: '库存必须填写',
                    digits: '请输入整数',
                    min: '库存最小值为0'
                },
            };
            _validate(formId, urles, messages)
        },

        //索特
        validate_menu: function (formId, mt) {
            var urles = {
                menu_control: {
                    required: true,
                    regex: "^[A-Za-z]+$",
                    rangelength: [2, 15],
                    remote: {
                        url: '/admin/menu/check_top_menu_unique?mark=' + mt,
                        type: 'get',
                        dataType: 'json',
                    }
                },
                title: {
                    required: true,
                    rangelength: [1, 20],
                },
                menu_action: {
                    required: true,
                    regex: "^[A-Za-z]+$",
                    rangelength: [2, 15],
                },
            };
            var messages = {
                menu_control: {
                    required: '控制器字段必填',
                    regex: "控制器字段为字母，输入不正确",
                    rangelength: '控制器字段长度为2-15个字符',
                    remote: '该控制器字段已存在'
                },
                title: {
                    required: '栏目名称必填',
                    rangelength: '栏目名称长度为1-20个字符',
                },
                menu_action: {
                    required: '控制器访问方法必填',
                    regex: "控制器访问方法为字母，输入不正确",
                    rangelength: '控制器访问方法长度为2-15个字符',
                },
            };
            _validate(formId, urles, messages)
        },

        validate_child_menu: function (formId, mt, parentid) {
            var urles = {
                menu_control: {
                    required: true,
                    regex: "^[A-Za-z]+$",
                    rangelength: [2, 15],
                    remote: {
                        url: '/admin/menu/check_child_menu_unique?mark=' + mt + '&parentid=' + parentid,
                        type: 'get',
                        dataType: 'json',
                    }
                },
                title: {
                    required: true,
                    rangelength: [1, 20],
                },
                menu_action: {
                    required: true,
                    regex: "^[A-Za-z]+$",
                    rangelength: [2, 15],
                },
            };
            var messages = {
                menu_control: {
                    required: '控制器字段必填',
                    regex: "控制器字段为字母，输入不正确",
                    rangelength: '控制器字段长度为2-15个字符',
                    remote: '该控制器字段已存在'
                },
                title: {
                    required: '栏目名称必填',
                    rangelength: '栏目名称长度为1-20个字符',
                },
                menu_action: {
                    required: '控制器访问方法必填',
                    regex: "控制器访问方法为字母，输入不正确",
                    rangelength: '控制器访问方法长度为2-15个字符',
                },
            };
            _validate(formId, urles, messages)
        },
        validate_Weight: function (formId) {
            var urles = {
                weight: {
                    required: true,
                    digits: true,
                    min: 0
                },
            };
            var messages = {
                weight: {
                    required: '权重必须填写',
                    digits: '请输入整数',
                    min: '权重最小值为0'
                },
            };
            _validate(formId, urles, messages)
        },

        validate_profile: function (formId) {
            var urles = {
                title: {
                    required: true,
                },
                keyword: {
                    maxlength: 200
                },
                description: {
                    maxlength: 200
                }
            };
            var messages = {
                title: {
                    required: '标题 必须填写',
                },
                keyword: {
                    maxlength: "关键字最长为200个字符"
                },
                description: {
                    maxlength: "描述最长为200个字符"
                }
            };
            _validate(formId, urles, messages)
        },

        validate_cooperation: function (formId) {//新闻表单验证
            var urles = {
                weight: {
                    required: true,
                    digits: true,
                    min: 0
                },
                title: {
                    required: true,
                },
                contents: {
                    maxlength: 62
                }
            };
            var messages = {
                weight: {
                    required: '权重必须填写',
                    digits: '请输入整数',
                    min: '权重最小值为0'
                },
                title: {
                    required: '标题必须填写',
                },
                contents: {
                    maxlength: "描述最长为62个字符"
                }
            };
            _validate(formId, urles, messages)
        },
        validate_cooperationWeight: function (formId) {//新闻列表权重验证
            var urles = {
                weight: {
                    required: true, 
                    digits: true,
                    min: 0
                },
            };
            var messages = {
                weight: {
                    required: '权重必须填写',
                    digits: '请输入整数',
                    min: '权重最小值为0'
                },
            };
            _validate(formId, urles, messages)
        },

        validate_contents: function (formId) {//新闻表单验证
            var urles = {
                title: {
                    required: true,
                },
                keyword: {
                    maxlength: 200
                },
                description: {
                    maxlength: 200
                }
            };
            var messages = {
                title: {
                    required: '标题必须填写',
                },
                keyword: {
                    maxlength: "关键字最长为200个字符"
                },
                description: {
                    maxlength: "描述最长为200个字符"
                }
            };
            _validate(formId, urles, messages)
        },
 
        validate_product: function (formId) {//新闻表单验证
            var urles = {
                title: {
                    required: true,
                },
                keyword: {
                    maxlength: 200
                },
                description: {
                    maxlength: 200
                },
                imgurl:{
                    required: true,
                }
            };
            var messages = {
                title: {
                    required: '标题必须填写',
                },
                keyword: {
                    maxlength: "关键字最长为200个字符"
                },
                description: {
                    maxlength: "描述最长为200个字符"
                },
                imgurl: {
                    required: '图片必须上传',
                }
            };
            _validate(formId, urles, messages)
        },
        validate_website: function (formId) {//新闻表单验证
            var urles = {
                title: {
                    required: true,
                },
             
                imgurl: {
                    required: true,
                }
            };
            var messages = {
                title: {
                    required: '标题必须填写',
                },
               
                imgurl: {
                    required: '图片必须上传',
                }
            };
            _validate(formId, urles, messages)
        },
        validate_banner: function (formId) {//新闻表单验证
            var urles = {
                weight: {
                    required: true,
                    digits: true,
                    min: 0,
                },
                imgurl: {
                    required: true,
                }
            };
            var messages = {
                weight: {
                    required: '权重必须填写',
                    digits: '请输入整数',
                    min: '权重最小值为0',
                    //isZipCode: '请正确填写您的邮政编码'
                },
                imgurl: {
                    required: '图片必须上传',
                }
            };
            _validate(formId, urles, messages)
        },
    });
}(jQuery))